/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.ucsur.datos;

import edu.ucsur.clases.Cliente;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 *
 * @author Miguel Angel
 */
public class BDCliente {
    
     public static Cliente buscarClienteRuc(String ruc) throws SQLException {
        return buscarClienteRuc(ruc, null);
    }

    public static Cliente buscarClienteRuc(String ruc, Cliente c) throws SQLException {
        Connection cnn = BD.getConnection();
        PreparedStatement ps = null;
        ps = cnn.prepareStatement("select nCliCodigo,cCliCi,cCliNombre,cCliDireccion,cCliNumTelefono,cCliTipoTelefono,cCliNroFax,cCliEmail,cCliOtros from cliente where cCliNit=?");
        ps.setString(1, ruc);
        ResultSet rs = ps.executeQuery();
        if (rs.next()) {
            if (c == null) {
                c = new Cliente() {
                };
            }
            c.setcCliRucDni(ruc);
            c.setnCliCodigo(rs.getInt("nCliCodigo"));
            c.setcCliNombre(rs.getString("cCliNombre"));
            c.setcCliDireccion(rs.getString("cCliDireccion"));
            c.setcCliNumTelefono(rs.getString("cCliNumTelefono"));
            c.setcCliTipoTelefono(rs.getString("cCliTipoTelefono"));
            c.setcCliNroFax(rs.getString("cCliNroFax"));
            c.setcCliEmail(rs.getString("cCliEmail"));
            c.setcCliOtros(rs.getString("cCliOtros"));
        }
        cnn.close();
        ps.close();
        return c;
    }

    
}
